<?php @session_start();
include 'clsSinhVien.php';
$sv = new SinhVien();
if(empty($_SESSION['sv'])){
	header("Location: sv-dangnhap.php");
}
$message = "";
 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trang Chủ Quản Trị</title>
<style type="text/css">
<!--
a	{
		color: #006600;
		text-decoration: none;
	}
.mau{background:#FFCC99;}
image{border:none;}

a:hover { COLOR: #CC0000}

.style1 {
	color: #FFFFFF;
	font-weight: bold;
	font-size: 30px;
}
.style2 {
	font-size: 18px;
	font-weight: bold;
	color: #FFFFFF;
  
}
.style3 {font-size: 14px; font-weight: bold; color: #FFFFFF; }
.style4 {color: #006600; font-weight: bold; font-size: 18px; }
.style5 {color:#0000000; font-weight: bold; font-size: 18px; }
.format {}
-->
</style>
<link rel="stylesheet" href="../css/jquery-ui-1.8.23.custom.css" type="text/css" media="all"/>
<script src="../js/jquery-1.8.2.min.js"></script>
<script src="../js/jquery.ui.core.js"></script>
<script src="../js/jquery.ui.datepicker.js"></script>

<script type="text/javascript">
	$(function() {	$("#datepicker").datepicker(); 
}); <!-- { dateFormat: 'dd/mm/yy'}
</script>
</head>

<body>
<?php if(isset($_POST['ghinhatki'])){
		if((isset($_POST['date']) && !empty($_POST['date'])) 
				&& (isset($_POST['content']) && !empty($_POST['content']))){
		//echo "da nhan";
		$masv = $_SESSION['sv'];
		//echo $masv;
		$ngaynhap = $_POST['date'];
		
		$change = date('Y-m-d', strtotime($ngaynhap));
		//echo $change;
		$noidungnhap = $_POST['content'];
		
		$mahocphan = $_GET['mahocphan'];
		$nhomhp = $_GET['nhomhocphan'];
		$hocki = $_GET['hocki'];
		$namhoc = $_GET['namhoc'];
		
		$getnoidungSV = $sv->getNoiDungSV($mahocphan, $nhomhp, $hocki, $namhoc, $masv, $change);
		$getnoidungGV = $sv->getNoiDungGV($mahocphan, $nhomhp, $hocki, $namhoc, $change);
		
		/* echo $getnoidungSV[0][0];
		
		echo $getnoidungGV[0][0]; */
		if($getnoidungGV[0][0] != null){  // da dc ghi
			if($getnoidungSV[0][0] == null) {
				$sv->updateNhatKi($mahocphan, $nhomhp, $hocki, $namhoc, $masv, $noidungnhap, $change);
				$message = '<ul style="color: green; font-size: 18px"><li>Đã ghi xong nhật kí</li></ul>';
			}
			else {
				$message = '<ul style="color: red; font-size: 18px"><li>Đã ghi nhật kí, không thể ghi lại.</li></ul>';
			}
		} else { // chua dc ghi
			
			$sv->setNhatKi($mahocphan, $nhomhp, $hocki, $namhoc, $masv, $noidungnhap, $change);
			$message = '<ul style="color: green; font-size: 18px"><li>Đã ghi xong nhật kí</li></ul>';
		}
		/* if($sv->testDate($ngaynhap)){ // ngay nhap = ngay co trong he thong
			if(!empty($masv) && !empty($mahocphan) && !empty($nhomhp) && !empty($hocki) && !empty($namhoc)
					&& !empty($ngaynhap) && !empty($noidungnhap)){
				$trangthai = $sv->getTrangThai($mahocphan, $nhomhp, $hocki, $namhoc, $masv, $change);
				echo $trangthai[0][0];
				if($trangthai[0][0] == 0) {
					$message = '<ul style="color: red; font-size: 18px"><li>Đã ghi nhật kí, không thể ghi lại.</li></ul>';
				} else {
					/* $sv->updateNhatKi($mahocphan, $nhomhp, $hocki, $namhoc, $masv, $noidungnhap, $change);
					$message = '<ul style="color: green; font-size: 18px"><li>Đã ghi xong nhật kí</li></ul>'; 
				}
			}
		}
		else {
			if(!empty($masv) && !empty($mahocphan) && !empty($nhomhp) && !empty($hocki) && !empty($namhoc)
					&& !empty($ngaynhap) && !empty($noidungnhap)){
				$sv->setNhatKi($mahocphan, $nhomhp, $hocki, $namhoc, $masv, $noidungnhap, $change);
				$message = '<ul style="color: green; font-size: 18px"><li>Đã ghi xong nhật kí</li></ul>';
			}
		} */
		
	}
	else {
		if(empty($_POST['date']) && empty($_POST['content'])) {
			$message = '<ul style="color: red; font-size: 18px">
				<li>Chưa chọn ngày</li>
				<li>Chưa nhập nội dung giảng dạy</li></ul>'; 
		} else if(empty($_POST['date'])) {$message = '<ul style="color: red; font-size: 18px"><li>Chưa chọn ngày</li></ul>'; }
		else if(empty($_POST['content'])) {$message = '<ul style="color: red; font-size: 18px"><li>Chưa nhập nội dung giảng dạy</li></ul>'; }
	}
} ?>
<table width="900px" height="600px" border="0" bordercolorlight="#CCCCCC" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #CCCCCC">

<!-- đầu trang --> 	
    <tr> <td width="900px" height="70px" background="../image/header.gif">
    	
        <table width="100%" height="100%" border="0"> 
             <tr>
       		
				    <td width="10%" rowspan="2"><img src="../image/logo.gif" width="100%" height="70" /></td>
					
					<td width="70%" rowspan="2" height="70" align="center" style="font-size:24px"><div align="right">
					  <blockquote>
						<p><span class="style1">WEBSITE GHI NHẬT KÍ HỌC PHẦN</span></p>
					  </blockquote>
				  </div></td>
        
            </tr> 
			<?php 
			if(isset($_SESSION['sv']) && !empty($_SESSION['sv'])){
				$session = $_SESSION['sv'];
				//echo $session;
				$taikhoan = $sv->getTenSV($session);
			
			}?>
			<tr>
				<td width="32%" valign="bottom" colspan="2" align="right"> <table>
					  <tr><td valign="bottom">
				  		<div align="center" class="style3">Xin chào <?php echo $taikhoan[0][0]; ?> </div></td></tr> 
					  <tr><td valign="bottom">
					  <div align="center" class="style3" style="margin-right: 10px">
						 <a class="style3" href="../logout.php">Thoát</a></div></td></tr>
					  
				       </table>
			    </td> 
			</tr>
			
	    </table>
    
    </td> </tr>
<!--menu ngang -->
   <tr bordercolor="#999999" height="10" valign="top">
   </tr>

<!-- thân trang -->  	
    <tr valign="top"> 
    	<td width="70%" border="0">
	    	<form action="" method="post">
	    	<fieldset><legend><label>Ghi Nhật Kí</label></legend>
	    	<table>
	    	<tr><td><?php echo $message; ?></td></tr>
	    		<tr>
	    			<td><label>Ngày nhập:</label><input name="date" type="text" id="datepicker"
	    				 value="<?php if(isset($_POST['date'])) echo $_POST['date'];?>" readonly="readonly" /></td>
	    		</tr>
	    		<tr>
	    			<td><label>Nội dung đã giảng: </label><input type="text" name="content" 
	    				value="<?php if(isset($_POST['content'])) echo $_POST['content'];?>" style="width: 300px"/></td>
	    		</tr>
	    		<tr><td><input type="submit" name="ghinhatki" value="Ghi nhật kí" /></td></tr>
	    	</table>
	    	</fieldset>
	    	</form>
    		
    	</td>
	</tr>
	<tr valign="top">
		<td valign="top">
			<table width="80%" bordercolor="#266886" cellspacing="0" cellpadding="0" align="center" border="1">
				<tr><td height="35px" colspan="3" align="center" style="background-color: #266886">
					<span style="font-size:18px; color:#FFFFFF; font-weight:bold;">Bảng Nhật Kí</span></td></tr>
				<tr align="center">
					<td>Stt</td>
					<td>Ngày giảng dạy</td>
					<td>Nội dung giảng dạy</td>
				</tr>
				<?php
					if(!empty($_GET['mahocphan']) && !empty($_GET['nhomhocphan']) 
							&& !empty($_GET['hocki']) && !empty($_GET['namhoc']) && isset($_SESSION['sv'])){
						$mahocphan = $_GET['mahocphan'];
						$nhomhp = $_GET['nhomhocphan'];
						$hocki = $_GET['hocki'];
						$namhoc = $_GET['namhoc'];
						$masv = $_SESSION['sv'];
						
						$getNK = $sv->getNhatKi($mahocphan, $nhomhp, $hocki, $namhoc, $masv);
						
						//print_r($getNK);
						foreach ($getNK as $nhatki){
						echo '<tr><td align="center"></td>
							<td align="center">'.date('d-m-Y', strtotime($nhatki[0])).'</td><td align="center">'.$nhatki[1].'</td></tr>';
						}
					}
				 ?>
			</table>
		</td>
	</tr>
	
	
<!-- cuối trang -->  
	<tr> 
	      <td height="28" background="../image/footer.gif" class="styles3" align="center" > Copyright @ by Nhóm phát triển
	     </td>
    </tr>
<!-- het cuoi trang-->

</table>

</body>
</html>


